<template>
  <div class="app-container">
    <el-card class="box-card" shadow="never" style="border:0px;">
      <div slot="header" style="color:#303133;font-size:14px;font-weight:bold;">
        <span>消息列表</span>
      </div>
    <div class="filter-container">
      <div class="left">
        <el-form :inline="true" class="demo-form-inline" size="medium" label-position="right" la>
          <el-form-item label="消息状态：" >
            <el-select v-model="listQuery.isRead" placeholder="请选择" style="width:100%;">
              <el-option label="未读" value="1" @click.native="listByPage()"></el-option>
              <el-option label="已读" value="2" @click.native="listByPage()"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="发布时间：">
            <el-date-picker
              class="date_item"
              v-model="listQuery.sendStartDate"
              type="datetime"
              placeholder="选择开始时间"
              align="right"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
            -<el-date-picker
              class="date_item"
              v-model="listQuery.sendEndDate"
              type="datetime"
              placeholder="选择结束时间"
              align="right"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
        </el-form>
      </div>
      <div class="right">
        <el-button type="primary" @click="listByPage(listQuery)">查询</el-button>
        <el-button @click="restForm">重置</el-button>
      </div>
    </div>
    <!--background-color:#ccc;-->
    <el-form :data="queryData" style="" v-loading="loading">
      <el-card v-for="(item, index) in queryData" :key="index" class="box-card" shadow="never" style="margin-top: 20px">
        <el-badge :is-dot="item.isRead === 1" class="item" style="font-size: 17px; font-weight: bold">消息通知</el-badge> <span>{{ item.sendTime }}</span><br />
        <span v-html="item.content"></span>，
          <a @click="toListList(item)" style="color: #db3ce6">点击查看</a>
          <el-button style="float: right; white-space: nowrap" type="primary" size="mini" plain v-if="item.ifDeal === true" @click="toListList(item)">立即处理</el-button>
          <el-button style="float: right; white-space: nowrap" type="success" size="mini" plain v-if="item.ifDeal === false">已处理</el-button>
      </el-card>
    </el-form>
     <!--<vxe-pager
      style="margin-right: 55%; margin-top: 30px"
      @page-change="changePage"
      :current-page.sync="listQuery.pageNo"
      :page-size.sync="listQuery.pageSize"
      :total="total"
      :page-sizes="[10, 50, 100,500,1000,{ label: '全量数据', value: -1 }]"
      :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump']"
    >
    </vxe-pager>-->
    </el-card>
    <vxe-pager
      class="pager"
      @page-change="changePage"
      :current-page.sync="listQuery.pageNo"
      :page-size.sync="listQuery.pageSize"
      :total="total"
      :page-sizes="[5, 10, 50,100]"
      :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']"
    >
    </vxe-pager>


  </div>
</template>

<script>
import { listByPage, update } from '@/api/notice';
import DicSelect from '@/components/select/index';
export default {
  name: 'User',
  components: { DicSelect },
  data: function () {
    return {
      active: 0,
      queryData: [],
      total: 0,
      listQuery: {
        pageNo: 1,
        pageSize: 5,
        isRead: undefined,
        sendStartDate: undefined,
        sendEndDate: undefined,
      },
      loading: true,
    };
  },
  mounted: function () {
    this.listByPage();
  },
  // getTask
  methods: {
    // 列表查询
    listByPage() {
      this.loading = true;
      listByPage(this.listQuery).then((data) => {
        this.queryData = data.data;
        this.total = data.total;
        console.log('响应数据:%o', data);
        this.loading = false;
      });
    },

    // 修改
    update(param) {
      this.loading = true;
      param.isRead = 2;
      update(param).then((data) => {
        if (param.ifDeal == false) {
          this.$message.error('该任务已被处理！');
          this.loading = false;
          return false;
        }
        this.loading = false;
      });
    },
    changePage() {
      this.listByPage();
    },
    // 跳转到任务列表
    toListList(row) {
      this.update(row);
      if (row.ifDeal == true) {
        this.$router.push({
          path: '/task/task_list',
          query: { taskId: row.taskId },
        });
      }
    },
    restForm() {
      this.listQuery = {
        pageNo: 1,
        pageSize: 10,
        isRead: undefined,
        sendStartDate: undefined,
        sendEndDate: undefined,
      };
      this.listByPage();
    },
  },
};
</script>

<style lang="css" scoped>
.filter-container {
  display: flex;
  justify-content: space-between;
}

.pager{
  position: fixed;
  bottom: 0;
  right: 28px;
  background-color: #FAFAFB;
  z-index: 2;
  height: 40px;
  width: calc(100% - 260px);
  }

.right >>> .el-button--primary,.el-button--default {
  padding: 10px 20px;
}

.left {
  flex: 14;
  display: flex;
  flex-flow: row wrap;
  margin-right: 20px;
}
.left >>> .el-form {
  width: 100%;
}
.left >>> .el-form .el-form-item {
  display: flex;
  flex-flow: row nowrap;
  width: 30%;
  margin-right: 3%;
  float: left;
  margin-bottom: 14px;
}

.left >>> .el-form .el-form-item .el-form-item__label {
  font-weight: 500;
  color: #606266;
  text-align: left;
  /* flex: 1; */
}

.left >>> .el-form .el-form-item .el-form-item__content {
  flex: 1;
  /*超出部分隐藏*/
  text-overflow: ellipsis;
  /* 超出部分显示省略号 */
  white-space: nowrap;
  /*规定段落中的文本不进行换行 */
  width: 100%;
}
.date_item {
  width: 100%;
}
.right {
  flex: 2;
  display: flex;
  flex-flow: row nowrap;
  align-items: flex-end;
  margin-right: 30px;
}
</style>
